package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venueservice.dto.HomeBuilderDrawingAuditPageQuery;
import com.eastfair.venueservice.dto.HomeBuilderDrawingAuditSaveDTO;
import com.eastfair.venueservice.dto.HomeBuilderDrawingAuditUpdateDTO;
import com.eastfair.venueservice.entity.HomeBuilderDrawingAudit;
import com.eastfair.venueservice.service.HomeBuilderDrawingAuditService;
import com.eastfair.venueservice.vo.HomeBuilderDrawingAuditVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 主场搭建商图纸审核记录
 * </p>
 *
 * @author dqq
 * @date 2023-04-28
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/homeBuilderDrawingAudit")
@Api(value = "HomeBuilderDrawingAudit", tags = "主场搭建商图纸审核记录")
@PreAuth(replace = "venueservice:homeBuilderDrawingAudit:")
public class HomeBuilderDrawingAuditController extends SuperController<HomeBuilderDrawingAuditService, Long, HomeBuilderDrawingAudit, HomeBuilderDrawingAuditPageQuery, HomeBuilderDrawingAuditSaveDTO, HomeBuilderDrawingAuditUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private HomeBuilderDrawingAuditService homeBuilderDrawingAuditService;

    @Override
    public void handlerResult(IPage<HomeBuilderDrawingAudit> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<HomeBuilderDrawingAudit> homeBuilderDrawingAuditList = list
                .stream()
                .map((map) -> HomeBuilderDrawingAudit.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(homeBuilderDrawingAuditList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<HomeBuilderDrawingAuditPageQuery> params) {
        HomeBuilderDrawingAuditPageQuery pageQuery = params.getModel();
    }

    /**
     * 图纸分类审核ID查询图纸列表.
     *
     * @param categoryAuditId the category audit id
     * @return the by drawing category id
     */
    @GetMapping("/get/by/categoryAuditId/{categoryAuditId}")
    public R<List<HomeBuilderDrawingAuditVO>> getByDrawingCategoryId(@PathVariable("categoryAuditId") Long categoryAuditId) {
        log.info("getByDrawingCategoryId - 图纸分类审核ID查询图纸列表, categoryAuditId={}", categoryAuditId);
        return R.successDef(homeBuilderDrawingAuditService.listDrawingVOByCategoryId(categoryAuditId));
    }
}
